/*
* 第三方支付通道模型
* */
import 'package:flutter_component_pay/flutter_component_pay.dart';
import 'package:flutter_component_pay/src/theme.dart';

class AbsThirdChannel {
  /// 支付类型（1=app，2=h5）
  final int? payType;

  /// 交易方式（1=wechat，2=alipay，3=unionpay）
  final int? tradeWay;

  /// 自定义属性
  final String logoName; // 支付通道logo
  final String payWayName; // 支付通道名
  final AbsPayWay way; // 支付方式
  bool isSelected; // 是否选择了此支付方式

  AbsThirdChannel({
    this.payType,
    this.tradeWay,
    // 自定义属性
    this.logoName = '',
    this.payWayName = '',
    this.way = AbsPayWay.wxPay,
    this.isSelected = false,
  });

  factory AbsThirdChannel.fromMap(Map<String, dynamic> json) {
    int? payType = json['payType'];
    int? tradeWay = json['tradeWay'];
    String logoName = '';
    String payWayName = '';
    AbsPayWay way = AbsPayTheme.defaultPayWay;

    // 支付图片名称
    if (tradeWay == 1) {
      logoName = 'wxpay';
      payWayName = '微信支付';
      way = AbsPayWay.wxPay;
    } else if (tradeWay == 2) {
      logoName = 'alipay';
      payWayName = '支付宝支付';
      way = AbsPayWay.aliPay;
    } else if (tradeWay == 3) {
      logoName = 'union';
      payWayName = '银联支付';
      way = AbsPayWay.union;
    }

    return AbsThirdChannel(
      payType: payType,
      tradeWay: tradeWay,
      logoName: logoName,
      payWayName: payWayName,
      way: way,
      isSelected: AbsPayTheme.defaultPayWay == way,
    );
  }

  Map<String, dynamic> toMap() => {
        'payType': payType,
        'tradeWay': tradeWay,
      };
}
